<?php
namespace Home\Controller;
use Think\Controller;
//个人管理

class AccountManageController extends MainController {
	/* <-------------                     学院管理                         -------------> */
	public function college_manage() {
		$this -> assign('tea_sel_add',$this->event->getTeacherList());
		$this -> display();
	}
    public function college_manage_ShowDatatables() {
	    $college_info = $this->school -> getCollegeInfoListWithTeacherName();
        $result['aaData'] = $college_info;
        echo json_encode($result);
	}
    public function add_college(){
    	$data = I();
        $result = $this->event->add_data($this->school_dao,$data);
        echo json_encode($result);
    }
    public function edit_college(){
        $data = I();
        $result = $this->event->edit_data($this->school_dao,$data);
        echo json_encode($result);
    }
    public function delete_college(){
        $data = I();
        $result = $this->event->delete_data($this->school_dao,$data);
        echo json_encode($result);
    }
	/* <-------------                     系部管理                         -------------> */
	public function department_manage() {
        $this -> assign('college_info', $this->event->getCollegeList());
		$this -> assign('par_college', $this->event->getCollegeList());
		$this -> assign('par_college_edit', $this->event->getCollegeList());
		$this -> assign('par_teacher', $this->event->getTeacherList());
		$this -> assign('par_teacher_edit', $this->event->getTeacherList());
		$this -> display();
	}
	public function department_manage_ShowDatatables() {

		$sch_id = I('sch_id');
		$department_info = $this->department->getCollegeInfoListWithTeacherName($sch_id);
		$result['aaData'] = $department_info;
        echo json_encode($result);
	}
	public function add_department(){
        $data = I();
        $result = $this->event->add_data($this->department_dao,$data);
        echo json_encode($result);
    }
    public function edit_department(){
        $data = I();
        $result = $this->event->edit_data($this->department_dao,$data);
        echo json_encode($result);
    }
    public function delete_department(){
        $data = I();
        $result = $this->event->delete_data($this->department_dao,$data);
        echo json_encode($result);
    }
	/* <-------------                       专业管理                         -------------> */
	public function noun_manage() {
        $this -> assign('college_info', $this->event->getCollegeList());
		$this -> assign('par_college', $this->event->getCollegeList());
		$this -> assign('par_college_edit', $this->event->getCollegeList());
		$this -> assign('department_info', $this->event->getDepatmentList());
		$this -> assign('par_department', $this->event->getDepatmentList());
		$this -> assign('par_department_edit', $this->event->getDepatmentList());
		$this -> assign('par_teacher', $this->event->getTeacherList());
		$this -> assign('par_teacher_edit', $this->event->getTeacherList());
		$this -> display();
	}
	public function noun_manage_ShowDatatables() {
		$dept_id = I('dept_id');
        $profession_info = $this->profession->getProfeesionInfoListWithTeacherName($dept_id);
		$result['aaData'] = $profession_info;
		echo json_encode($result);
	}
    public function add_noun(){
        $data = I();
        $result = $this->event->add_data($this->profession_dao,$data);
        echo json_encode($result);
    }
    public function edit_noun(){
        $data = I();
        $result = $this->event->edit_data($this->profession_dao,$data);
        echo json_encode($result);
    }
    public function delete_noun(){
        $data = I();
        $result = $this->event->delete_data($this->profession_dao,$data);
        echo json_encode($result);
    }
	/* <-------------                       班级管理                         -------------> */
	public function class_manage() {
	    $this -> assign('college_info', $this->event->getCollegeList());
		$this -> assign('par_college', $this->event->getCollegeList());
		$this -> assign('par_college_edit', $this->event->getCollegeList());
		$this -> assign('department_info', $this->event->getDepatmentList());
		$this -> assign('par_department', $this->event->getDepatmentList());
		$this -> assign('par_department_edit', $this->event->getDepatmentList());
		$this -> assign('noun_info', $this->event->getProfessionList());
		$this -> assign('par_noun', $this->event->getProfessionList());
		$this -> assign('par_noun_edit', $this->event->getProfessionList());
		$this -> display();
	}
	public function class_manage_ShowDatatables() {
		$noun_id = I('noun_id');
        $class_info = $this->naturalclass->getNaturalInfoList($noun_id);
		$result['aaData'] = $class_info;
		echo json_encode($result);
	}
    public function add_class(){
        $data = I();
        $result = $this->event->add_data($this->naturalclass_dao,$data);
        echo json_encode($result);
    }
    public function edit_class(){
        $data = I();
        $result = $this->event->edit_data($this->naturalclass_dao,$data);
        echo json_encode($result);
    }
    public function delete_class(){
        $data = I();
        $result = $this->event->delete_data($this->naturalclass_dao,$data);
        echo json_encode($result);
    }
    /* <-------------                       教师管理                         -------------> */
	//教师管理
	public function teacher_manage(){
	    $this -> assign('college_info', $this->event->getCollegeList());
		$this -> assign('par_college', $this->event->getCollegeList());
		$this -> assign('par_college_edit', $this->event->getCollegeList());
		$this -> assign('department_info', $this->event->getDepatmentList());
		$this -> assign('par_department', $this->event->getDepatmentList());
		$this -> assign('par_department_edit', $this->event->getDepatmentList());
		$this->display();
	}
	public function teacher_manage_ShowDatatables(){
		$department_id = I('department_id');
		$tea_num = I('tea_num');
		$teacher_info = $this->teacher->getTeacherInfoByDepIDAndTeaNum($department_id,$tea_num);
        $result['aaData'] = $teacher_info;
        echo json_encode($result);
	}
	public function add_teacher(){
        $data = I();
        $result = $this->event->add_data($this->teacher_dao,$data);
        echo json_encode($result);
    }
    public function edit_teacher(){
        $data = I();
        $result = $this->event->edit_data($this->teacher_dao,$data);
        echo json_encode($result);
    }
    public function delete_teacher(){
        $data = I();
        $result = $this->event->delete_data($this->teacher_dao,$data);
        echo json_encode($result);
    }
    public function getCollegeAndDepartmentName(){
        $department_id = I('department_id');
        $info = $this->department->getCollegeAndDepartmentName($department_id);
        if ($info){
            $res['state'] = true;
            $res['info'] = $info;
        }else{
            $res['state'] = false;
            $res['info'] = array();
        }
        echo json_encode($res);
    }
    public function course_info_ShowDatatables(){
        $department_id = I('department_id');
        $teacher_id = I('tea_id');
        $course_info = $this->course->getCourseInfoListForTeacherNounByDepartment($department_id,$teacher_id);
        $result['aaData'] = $course_info;
        echo json_encode($result);
    }
    public function teacher_course_ShowDatatables(){
        $teacher_id = I('teacher_id');
        $teacher_course_info = $this->teachercourse->getTeacherCourseNounInfoList($teacher_id);
        $result['aaData'] = $teacher_course_info;
        echo json_encode($result);
    }
    public function addTeacherCourseNoun(){
        $department_id =I('department_id');
        $teacher_id = I('teacher_id');
        $info = $this->teachercourse_dao->addTeacherCourseNoun($teacher_id,$department_id);
        $result['state'] = $info ? true : false;
        echo json_encode($result);
    }
    public function deleteTeacherCourseNoun(){
        $department_id =I('department_id');
        $teacher_id = I('teacher_id');
        $info = $this->teachercourse_dao->deleteTeacherCourseNoun($teacher_id,$department_id);
        $result['state'] = $info ? true : false;
        echo json_encode($result);
    }
    /* <-------------                       学生管理                         -------------> */
    //学生管理
    public function student_manage() {
        $this -> assign('college_info', $this->event->getCollegeList());
        $this -> assign('par_college', $this->event->getCollegeList());
        $this -> assign('par_college_edit', $this->event->getCollegeList());
        $this -> assign('par_college_export', $this->event->getCollegeList());
        $this -> assign('department_info', $this->event->getDepatmentList());
        $this -> assign('par_department', $this->event->getDepatmentList());
        $this -> assign('par_department_edit', $this->event->getDepatmentList());
        $this -> assign('par_department_export', $this->event->getDepatmentList());
        $this -> assign('noun_info', $this->event->getProfessionList());
        $this -> assign('par_noun', $this->event->getProfessionList());
        $this -> assign('par_noun_edit', $this->event->getProfessionList());
        $this -> assign('par_noun_export', $this->event->getProfessionList());
        $this -> assign('class_info',$this->event->getNaturalClassList());
        $this -> assign('par_class',$this->event->getNaturalClassList());
        $this -> assign('par_class_edit',$this->event->getNaturalClassList());
        $this -> assign('par_class_export',$this->event->getNaturalClassList());
        $this -> display();
    }
    public function student_manage_ShowDatatables(){
        $class_id = I('class_id');
        $stu_num = I('stu_num');
        $student_info = $this->student-> getStudentInfoByClassIdAndStuNum($class_id,$stu_num);
        $result['aaData'] = $student_info;
        echo json_encode($result);
    }
    public function add_student(){
        $data = I();
        $result = $this->event->add_data($this->student_dao,$data);
        echo json_encode($result);
    }
    public function edit_student(){
        $data = I();
        $result = $this->event->edit_data($this->student_dao,$data);
        echo json_encode($result);
    }
    public function delete_student(){
        $data = I();
        $result = $this->event->delete_data($this->student_dao,$data);
        echo json_encode($result);
    }
    public function downLoadExcel(){

        //$root = __ROOT__;
        $filename = './UploadExcel/stu.xls';
        $showname = '模板(请删除示例后添加学生信息).xls';
        $http = new \Org\Net\Http();
        $http->download($filename,$showname);
        $result['state'] = true;
        echo json_encode($result);
    }
    public function UploadExcel(){

        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize = 3145728 ;// 设置附件上传大小
        $upload->exts = array('xls', 'xlsx');// 设置附件上传类型
        $upload->rootPath = './ExcelUpload/'; // 设置附件上传根目录

        $config = array('rootPath' => './UploadExcel/', 'subName' => time(), );
        $upload = new \Think\Upload($config);

        $upload->autoSub = false;
        // 上传文件
        $info = $upload->upload();
        if(!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
        }else{// 上传成功
            // $this->success('上传成功！');
//            $root = __ROOT__;
            $filename = $upload->rootPath . $info['upload_file']['savename'];
            $data= $this->event->import_excel($filename);
            $info = $this->event->mapDataFromExcel($data);
            $result['state'] = true;
            $result['list'] = $info;
            unlink($filename);
            echo json_encode($result);
        }
    }
    public function export_student(){
        $data = I('data_list');
        $result = array('state'=>true,'info'=>'');
        foreach ($data as $key => $value){
            $info = $this->event->add_data($this->student_dao,$value);
            if (!$info['state']){
                $result['state'] = false;
                $result['info'] = $info['state'] . $result['info'] ;
            }
        }
        if ($result['state']){
            $result['info'] = '导入成功';
        }
        echo json_encode($result);
    }





}
?>